import request from "@/utils/request";
import type { UploadUserFile } from 'element-plus'
import {Attachment,IObject} from "@/api/common/common";
import httpRequest from "@/utils/requestUtil";
import CommonUtil from "@/utils/commonUtil";

const GOODS_BANNER_BASE_URL = "/goods/banner";

const GoodsBannerAPI = {


  /**
   * 获取商品分页列表
   *
   * @param queryParams 查询参数
   */
  getPage(queryParams: GoodsBannerPageQuery) {
    return request<any, PageResult<GoodsBannerPageVO[]>>({
      url: `${GOODS_BANNER_BASE_URL}/loadPage`,
      method: "get",
      params: queryParams,
    });
  },


  /**
   * 获取商品表单详情
   *
   * @param id 商品ID
   * @returns 商品表单详情
   */
  getFormData(id: string) {
    return request<any, GoodsBannerPageVO>({
      url: `${GOODS_BANNER_BASE_URL}/load/${id}`,
      method: "get",
    });
  },



  updateDisplay(id:string, display: boolean) {
    return request<any, any>({
      url: `${GOODS_BANNER_BASE_URL}/display?id=${id}&display=${display}`,
      method: "get",
    });
  },

    /**
   * 添加商品
   *
   * @param data 商品表单数据
   */
  create(data: GoodsBannerForm) {
    // 修复ts编译错误：FormData不存在entries方法
    // @ts-ignore
    return httpRequest.post<PageResult<GoodsBannerPageVO>>(`${GOODS_BANNER_BASE_URL}/add`, data);
  },

  /**
   * 修改商品
   *
   * @param id 商品ID
   * @param data 商品表单数据
   */
  update(id: string, data: GoodsBannerForm) {
    // 修复ts编译错误：FormData不存在entries方法
    // @ts-ignore
    return httpRequest.post<PageResult<GoodsBannerPageVO>>(`${GOODS_BANNER_BASE_URL}/update`, data);
  },



  /**
   * 批量删除商品，多个以英文逗号(,)分割
   *
   * @param ids 商品ID字符串，多个以英文逗号(,)分割
   */
  deleteByIds(ids: string) {
    return request({
      url: `${GOODS_BANNER_BASE_URL}/batchDelete?ids=${ids}`,
      method: "get",
    });
  },



};

export default GoodsBannerAPI;


/**
 * 商品分页查询对象
 */
export interface GoodsBannerPageQuery extends PageQuery {
 
  display?: boolean;

}

/** 商品分页对象 */
export interface GoodsBannerPageVO {
    /** 商品ID */
    id?: string;
    /** 商品名称 */
    name?: string;

    attachId?: string;
    display?: boolean;
    remark?: string;
    relatedId?: string;
    relatedType?: string;
    relatedName?: string;
    imageUrl?: string;

}



export interface GoodsBannerForm {

    /** 商品ID */
    id?: string;
    /** 商品名称 */
    name?: string;

    attachId?: string;
    display?: boolean;
    remark?: string;
    relatedId?: string;
    relatedType?: string;
    attachmentIds?: string[];
}



export enum GoodsBannerType { 
  SaleMeal = 'SaleMeal',
  Goods = 'Goods',

}


export const GoodsRelatedType_LABEL: IObject = {
  [GoodsBannerType.SaleMeal]: '套餐',
  [GoodsBannerType.Goods]: '商品',
}
